package com.ea.eadp.nexus.test.pageDefinition;
import com.ea.eadp.nexus.test.common.TestUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
 * Created by ChuanYe on 9/8/2014.
 */
public class EmailVerifyPage extends BasePage {
    private static final String successMessage = "Success! Your email has been verified.";
    private static final String resultElement = "resultText";
    protected String identifierId = "btnResend";

    public EmailVerifyPage(WebDriver driver) {
        super(driver, EmailVerifyPage.class);
    }
    public void waitPageLoadCompleted() {
        WebDriverWait wait = new WebDriverWait(driver, 30, 1000);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(identifierId)));
    }
    public void verify(String email, String code, boolean mockVerificationResult) {
        driver.switchTo().window(operationWindowHandle);
        String uri = TestUtil.getEmailVerifyUrl(email, code, mockVerificationResult);
        log.info(uri);
        driver.navigate().to(uri);
    }

    public boolean isVerifySuccess() {
        boolean success = driver.findElement(By.id(resultElement)).getText().contains(successMessage);
        return success;
    }
    public void resendVerifyEmail() {
        driver.switchTo().window(operationWindowHandle);
        driver.findElement(By.xpath(".//*[@id='btnResend']")).click();
    }

}
